package catherineliu.main.singleton.builder.food;

import java.util.ArrayList;
import java.util.List;

/**
 * 项目：DesignPatternsDemo
 * 文件描述：创建一个 Meal 类，带有上面定义的 Item 对象
 * 作者：ljj
 * 创建时间：2020/11/26
 */
public class Meal {
    private List<FoodItem> foodItems = new ArrayList<>();

    public void addItem(FoodItem foodItem) {
        foodItems.add(foodItem);
    }

    public float getCost() {
        float cost = 0.0f;
        for (FoodItem foodItem : foodItems) {
            cost += foodItem.price();
        }
        return cost;
    }

    public void showItems() {
        for (FoodItem foodItem : foodItems) {
            String stringBuilder = "Food: " + foodItem.name() +
                    ", Packing: " + foodItem.packing().pack() +
                    ", Price: " + foodItem.price();
            System.out.println(stringBuilder);
        }
    }

}
